﻿using System.Linq;
using System.Reflection;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Drapid.Domain.Configuration;
using DRapid.Utility.Exceptional.Routing;
using DRapid.Web.Unity;
using Owin;

namespace WebSite.Admin
{
    public partial class Startup
    {
        public void ConfigMvc(IAppBuilder app)
        {
            RemoveWebFormEngines();
            app.ResolveMvcDependency(AppConfiguration.Current.ComponentContainer);
            AreaRegistration.RegisterAllAreas();
            RegisterMvcGlobalFilters(GlobalFilters.Filters);
            RegisterBundles(BundleTable.Bundles);
            RegisterRoutes(RouteTable.Routes);
        }

        /// <summary>
        /// 移除webform的视图
        /// 说是让MVC加载视图的时候可以减少搜索量
        /// </summary>
        void RemoveWebFormEngines()
        {
            var viewEngines = ViewEngines.Engines;
            var webFormEngines = viewEngines.OfType<WebFormViewEngine>().FirstOrDefault();
            if (webFormEngines != null)
            {
                viewEngines.Remove(webFormEngines);
            }
        }
    }
}